home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / agblankers / source / sinus / blank.c next >
C/C++ Source or Header  |  1995-02-27  |  4KB  |  146 lines

  1. /* --------------------------------------------------------
  2.  *    Draw nice pictures based on a simple mathematical
  3.  *    formula
  4.  *                                           010294 kha.
  5.  * -------------------------------------------------------- */
  6.  
  7. #include <exec/memory.h>
  8. #include <math.h>
  9.  
  10. #include "/includes.h"
  11.  
  12. #define WINCO(SIZE,MAX) ((int) (( (int)((SIZE+2.0)*MAX) ) / 4 ) )
  13. #define bool int
  14. #ifndef TRUE
  15. #define TRUE 1
  16. #define FALSE 0
  17. #endif
  18.  
  19. Triplet *ColorTable = 0L;
  20.  
  21. #define LINEPICS 0
  22. #define VALRANGE 2
  23. #define DURATION 4
  24. #define DELAY 6
  25. #define MODE 8
  26.  
  27. VOID Defaults( PrefObject *Prefs )
  28. {
  29.     Prefs[LINEPICS].po_Level = 3;
  30.     Prefs[DURATION].po_Level = 100;
  31.         Prefs[VALRANGE].po_Level = 10;
  32.     Prefs[DELAY].po_Level = 0;
  33.     Prefs[MODE].po_ModeID = getTopScreenMode();
  34.     Prefs[MODE].po_Depth = 4;
  35. }
  36.  
  37. LONG Sinus( struct Screen *scr, SHORT width, SHORT height, PrefObject *Prefs)
  38. {
  39.   LONG flg_end = OK;
  40.   int colors = 1L << scr->BitMap.Depth;
  41.   int bigc, smallc;
  42.   int durationfactor,delay,lineprobability;  /* P = lineprobability / 7 */
  43.   int minval,valrange;
  44.  
  45.   struct RastPort *rp = &( scr->RastPort );
  46.  
  47.   durationfactor  = Prefs[DURATION].po_Level * 100 + 1000;
  48.   valrange        = Prefs[VALRANGE].po_Level;
  49.   delay           = Prefs[DELAY].po_Level;
  50.   lineprobability = Prefs[LINEPICS].po_Level;
  51.   width--; height--;
  52.   SetRast( rp, 0 );
  53.   ScreenToFront( scr );
  54.  
  55.   minval = valrange/2;
  56.   
  57.   bigc = 0;
  58.   while (bigc != 4096 && flg_end == OK)
  59.     { double a,b,c,d,step;
  60.       double x,y,z,delta,lasty,lastz;
  61.       int wx,wy,limit,dbl;
  62.       bigc++;
  63.       a = (double) (RangeRand(valrange)-minval);
  64.       b = (double) (RangeRand(valrange)-minval);
  65.       c = (double) (RangeRand(valrange)-minval);
  66.       d = (double) (RangeRand(valrange)-minval);
  67.       step = ((double)RangeRand(1000))/10000 + 0.05;
  68.         
  69.       if (RangeRand(7) >= lineprobability)
  70.         { if (RangeRand(2) == 0)
  71.             step =  (PI/2) - step;
  72.           else
  73.         step = PI + 0.05 + ((double)RangeRand(1000))/10000;
  74.         }
  75.  
  76.       x = 0.0;
  77.       limit = durationfactor / scr->BitMap.Depth;
  78.       if (step > 1) limit = limit / 2;
  79.       
  80.       wx = WINCO(1,width);
  81.       wy = WINCO(1,height);
  82.       Move(rp,wx,wy);
  83.       lasty = 1.0; lastz = 1.0;
  84.       
  85.       smallc=0;
  86.       SetRast(rp,0);
  87.       while (smallc<limit && flg_end == OK)
  88.         { y = sin(a*x)+cos(b*x);
  89.           z = sin(c*x)+cos(d*x);
  90.           delta = fabs(y-lasty) + fabs(z-lastz);
  91.       SetAPen(rp,(int)(delta/4*(colors-1)+1));
  92.           wx = WINCO(y,width);
  93.           wy = WINCO(z,height);
  94.           Draw(rp,wx,wy);
  95.           x = x + step;
  96.           lasty = y; lastz = z;
  97.           if (smallc%64 == 0)
  98.             { ScreenToFront(scr);
  99.               flg_end = ContinueBlanking();
  100.             }
  101.       smallc++;
  102.         }
  103.       if (flg_end == OK && delay > 0)
  104.     { int curr = 0;
  105.           while (curr < delay * 10 && flg_end == OK)
  106.         { Delay(5);
  107.           ScreenToFront(scr);
  108.           flg_end = ContinueBlanking();
  109.           curr++;
  110.             }
  111.         }
  112.     }
  113.   return flg_end;
  114. }
  115.  
  116.  
  117. /* Adopted from the Dragon blanker */
  118. LONG Blank( PrefObject *Prefs )
  119. {
  120.     struct Screen *Scr;
  121.     struct Window *Wnd;
  122.     LONG RetVal;
  123.  
  124.     if( Scr = OpenScreenTags( NULL, SA_Depth, Prefs[MODE].po_Depth,
  125.                              SA_Quiet, TRUE, SA_DisplayID, Prefs[MODE].po_ModeID,
  126.                              SA_Behind, TRUE, SA_Overscan, OSCAN_STANDARD,
  127.                              TAG_DONE ))
  128.     {
  129.         SetRGB4(&( Scr->ViewPort ), 0, 0, 0, 0 );
  130.         ColorTable = RainbowPalette( Scr, 0L, 1L, 0L );
  131.         Wnd = BlankMousePointer( Scr );
  132.         
  133.         do
  134.             RetVal = Sinus( Scr, Scr->Width, Scr->Height, Prefs );
  135.         while( RetVal == OK );
  136.         
  137.         UnblankMousePointer( Wnd );
  138.         RainbowPalette( 0L, ColorTable, 1L, 0L );
  139.         CloseScreen( Scr );
  140.     }
  141.     else
  142.         RetVal = FAILED;
  143.     
  144.     return RetVal;
  145. }
  146.